package jmine.tec.persist.hibernate.initializer.domain;


import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Index;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;

/** 
 * @author wellington.santos
 * @created May 29, 2012
 */
@Entity
@Alias("TAB")
@Table(name = "DISCRIMINATED_TABLE")
@Documentation("TABELA DISCRIMINADA")
@SequenceGenerator(name = "SEQ_DISC_TAB", sequenceName = "SEQ_DISC_TAB")
@DiscriminatorColumn(name = "TIPO", discriminatorType = DiscriminatorType.INTEGER)
public abstract class DiscriminatedParentEntity extends PersistableBusinessObject {

    private Long id;
    
    private DiscriminatedParentEntity association;

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator = "SEQ_DISC_TAB")
    @Column(name = "COD_DISC_TAB", precision = 17, nullable = false)
    @Documentation("CODIGO TAB")
    public Long getId() {
        return this.id;
    }

    /**
     * @return the association
     */
    @Index(suffix = "JT_0")
    @ManyToOne(fetch = FetchType.LAZY)
    @Documentation("CODIGO DA ENTIDADE ASSOCIADA")
    @JoinColumn(name = "COD_ASSOC")
    public DiscriminatedParentEntity getAssociation() {
        return this.association;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param association the association to set
     */
    public void setAssociation(DiscriminatedParentEntity association) {
        this.association = association;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE);
    }

}

